package com.anjubao.parking.municipal.roadside.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.roadside.form.ParkingLotSlotForm;
import com.anjubao.parking.municipal.roadside.service.ParkingLotSlotService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/sync/slots")
public class ParkingLotSlotController {

    private static final Logger logger = LoggerFactory.getLogger(ParkingLotSlotController.class);

    @Autowired
    private ParkingLotSlotService parkingLotSlotService;

    /**
     * 车位信息
     * @param type（1：新增，2：修改）
     * @param slotForm
     * @return
     */
    @PostMapping(value = "/{type}")
    public ApiResult syncParkingLotSlot(@PathVariable int type, @RequestBody @Validated ParkingLotSlotForm slotForm) {
        logger.info("【新增或修改车位信息】,参数:{}", slotForm);
        parkingLotSlotService.syncParkingLotSlot(type,slotForm);
        return ApiResult.success();
    }
    /**
     * 删除车位
     * @param parkingLotSlotCode
     * @return
     */
    @GetMapping(value = "{parkingLotSlotCode}/delete")
    public ApiResult delParkingLotSlot( @PathVariable @Validated String parkingLotSlotCode) {
        logger.info("【删除车位】==>车位code:{}", parkingLotSlotCode);
        parkingLotSlotService.delParkingLotSlot(parkingLotSlotCode);
        return ApiResult.success();
    }

    /**
     * 获取车位状态
     * @param slots
     * @return
     */
    @GetMapping(value = "/state")
    public ApiResult<List> getLotSlotState(@RequestParam("slots") List<String> slots){
        //logger.info("【获取车位状态】==>参数：{}",slots);
        return ApiResult.success(parkingLotSlotService.getSlotState(slots));

    }

}

